(function () {
Client = function() {
	this.name = 'client';
	this.subscriber_onopen = new Array();
	this.subscriber_onmessage = new Array();
	this.subscriber_onclose = new Array();
	return this;
}
Client.prototype = {
	connect : function(ip, port) {
		console.log(['ws://', ip, ':', port, '/input'].join(''));
		this.ws = new WebSocket(['ws://', ip, ':', port, '/input'].join(''));
		this.ws.onopen = this.onopen.bind(this);
		this.ws.onmessage = this.onmessage.bind(this);
		this.ws.onclose = this.onclose.bind(this);
		this.ws.onerror = this.onerror.bind(this);
	},
	
	disconnect : function() {
		this.ws.close();
	},
	
	subscribe_onopen : function(callback) {
		this.subscriber_onopen.push(callback);
	},
	
	subscribe_onmessage : function(callback) {
		this.subscriber_onmessage.push(callback);
	},
	
	subscribe_onclose : function(callback) {
		this.subscriber_onclose.push(callback);
	},
	
	onopen : function(event) {
		console.log("client - onopen");
		console.log(this.subscriber_onopen);
		for (var i = 0; i < this.subscriber_onopen.length; i++) {
			console.log("Blurb");
			this.subscriber_onopen[i](event);
		}
	},
	onmessage : function(event) {
		console.log(event);
		for (var i = 0; i < this.subscriber_onmessage.length; i++) {
			this.subscriber_onmessage[i](event);
		}
	},
	send : function(data) {
		console.log("client sendet:", data)
		this.ws.send(JSON.stringify(data));
	},
	
	onclose : function(event) {
		console.log("Websocket closed!");
		for (var i = 0; i < this.subscriber_onclose.length; i++) {
			this.subscriber_onclose[i](event);
		}
	},
	
	onerror : function(event) {
		alert("Web error!")
	}
};

})();